<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import {
  uploadPictureByBatchUsingPost
} from '@/api/pictureController.ts'
import UrlPictureUpload from '@/components/UrlPictureUpload.vue'

const formData = reactive<API.PictureUploadByBatchRequest>({
  count: 10,
})
const loading = ref(false)

const router = useRouter()

const handleSubmit = async (values: any) => {
  loading.value = true;
  const res = await uploadPictureByBatchUsingPost({
    ...formData,
  })
  if (res.data.code === 0 && res.data.data) {
    message.success(`创建成功，共 ${res.data.data} 条`)
    router.push({
      path: '/',
    })
  } else {
    message.error('创建失败，' + res.data.message)
  }
  loading.value = false;
}
</script>

<template>
  <div class="batch-upload-container">
    <div class="content-wrapper">
      <!-- 页面头部 -->
      <div class="page-header">
        <div class="header-content">
          <h1 class="page-title">批量创建图片</h1>
          <p class="page-subtitle">通过关键词批量获取和创建图片资源</p>
        </div>
      </div>

      <!-- 表单卡片 -->
      <div class="form-card">
        <a-form
          layout="vertical"
          :model="formData"
          @finish="handleSubmit"
          class="upload-form"
        >
          <div class="form-group">
            <a-form-item label="搜索关键词" name="searchText" class="form-item">
              <a-input
                v-model:value="formData.searchText"
                placeholder="输入描述性关键词，如：风景、动物、建筑等"
                size="large"
                class="custom-input"
              />
            </a-form-item>
          </div>

          <div class="form-row">
            <div class="form-group flex-1">
              <a-form-item label="抓取数量" name="count" class="form-item">
                <a-input-number
                  v-model:value="formData.count"
                  placeholder="1-30"
                  size="large"
                  :min="1"
                  :max="30"
                  allow-clear
                  class="custom-input-number"
                />
              </a-form-item>
            </div>

            <div class="form-group flex-2">
              <a-form-item label="名称前缀" name="namePrefix" class="form-item">
                <a-input
                  v-model:value="formData.namePrefix"
                  placeholder="自定义前缀，系统将自动添加序号"
                  size="large"
                  class="custom-input"
                />
              </a-form-item>
            </div>
          </div>

          <div class="submit-section">
            <a-button
              type="primary"
              html-type="submit"
              :loading="loading"
              size="large"
              class="submit-button"
            >
              <template v-if="!loading">
                <span>开始批量创建</span>
              </template>
              <template v-else>
                <span>正在处理中...</span>
              </template>
            </a-button>
          </div>
        </a-form>
      </div>

      <!-- 提示信息 -->
      <div class="tips-section">
        <div class="tip-item">
          <div class="tip-icon">💡</div>
          <div class="tip-content">
            <div class="tip-title">使用建议</div>
            <div class="tip-text">使用具体、清晰的关键词能获得更好的搜索结果</div>
          </div>
        </div>
        <div class="tip-item">
          <div class="tip-icon">⚡</div>
          <div class="tip-content">
            <div class="tip-title">处理速度</div>
            <div class="tip-text">批量处理需要一定时间，请耐心等待</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.batch-upload-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  padding: 2rem 1rem;
}

.content-wrapper {
  max-width: 640px;
  margin: 0 auto;
}

/* 页面头部 */
.page-header {
  text-align: center;
  margin-bottom: 3rem;
}

.header-content {
  padding: 1rem 0;
}

.page-title {
  font-size: 2.25rem;
  font-weight: 300;
  color: #1a1a1a;
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 1rem;
  color: #6b7280;
  margin: 0;
  font-weight: 400;
}

/* 表单卡片 */
.form-card {
  background: white;
  border-radius: 16px;
  padding: 2.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.06);
  margin-bottom: 2rem;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-row {
  display: flex;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.flex-1 {
  flex: 1;
}

.flex-2 {
  flex: 2;
}

/* 表单项样式 */
:deep(.form-item .ant-form-item-label > label) {
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.5rem;
}

:deep(.custom-input) {
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

:deep(.custom-input:hover) {
  border-color: #d1d5db;
}

:deep(.custom-input:focus) {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

:deep(.custom-input-number) {
  width: 100%;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  transition: all 0.2s ease;
}

:deep(.custom-input-number:hover) {
  border-color: #d1d5db;
}

:deep(.custom-input-number:focus-within) {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 提交按钮 */
.submit-section {
  margin-top: 1rem;
}

.submit-button {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

:deep(.submit-button:hover) {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

:deep(.submit-button:active) {
  transform: translateY(0);
}

:deep(.submit-button.ant-btn-loading) {
  background: linear-gradient(135deg, #93c5fd 0%, #60a5fa 100%);
}

/* 提示信息 */
.tips-section {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

.tip-item {
  flex: 1;
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.tip-icon {
  font-size: 1.25rem;
  line-height: 1;
  margin-top: 0.125rem;
}

.tip-content {
  flex: 1;
}

.tip-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.25rem;
}

.tip-text {
  font-size: 0.8rem;
  color: #6b7280;
  line-height: 1.4;
}

/* 响应式设计 */
@media (max-width: 640px) {
  .batch-upload-container {
    padding: 1rem 0.75rem;
  }

  .content-wrapper {
    max-width: 100%;
  }

  .page-title {
    font-size: 1.875rem;
  }

  .form-card {
    padding: 1.5rem;
    border-radius: 12px;
  }

  .form-row {
    flex-direction: column;
    gap: 1rem;
  }

  .tips-section {
    flex-direction: column;
  }
}
</style>
